package main

import (
	"encoding/json"
	"jlpay-sdk-go/pkg/jlpay/demo"
	"jlpay-sdk-go/pkg/jlpay/models/ledger"
	ledger2 "jlpay-sdk-go/pkg/jlpay/services/ledger"
	"jlpay-sdk-go/pkg/jlpay/utils"
)

// 余额退款示例
func balanceRefundDemo() {
	config := demo.CreateDemoConfig()
	balanceSplitService := ledger2.NewBalanceSplitService(config)

	// 创建余额退款请求
	request := ledger.NewBalanceRefundRequest()

	// 直接使用map构建请求
	requestMap := map[string]interface{}{
		"org_code":      "50720711",
		"mch_id":        "849581183510017",
		"out_order_no":  "045e1314f7784f46bf9d590dc65c7",
		"out_return_no": "12e3045e13146bf9d590d12c65c11",
		"rev_mch_id":    "849584307420004",
		"amount":        100,
		"description":   "分账退回",
	}

	// 设置原始请求数据
	request.SetRawRequestMap(requestMap)

	// 序列化请求数据并打印
	requestJSON, _ := json.Marshal(requestMap)
	utils.Debugf("余额退款请求数据: %s", string(requestJSON))

	// 发送请求
	response, err := balanceSplitService.RefundBalance(request)
	if err != nil {
		utils.Errorf("余额退款请求失败: %v", err)
		return
	}

	// 处理响应 - 使用BaseResponse接口的HandleResponse方法
	response.HandleResponse("余额退款")
}

func main() {
	// 设置日志级别为info，显示详细的调试信息
	utils.SetLogLevel("info")

	utils.Info("=============================")
	utils.Info("===== 余额退款示例 开始 =====")
	utils.Info("=============================")

	balanceRefundDemo()

	utils.Info("=============================")
	utils.Info("===== 余额退款示例执行完毕 =====")
	utils.Info("=============================")
}
